home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 7255 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.9 KB

  1. Path: pegasus.montclair.edu!harmon
  2. From: harmon@pegasus.montclair.edu (Derek Harmon)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: string and NULL :question
  5. Date: 12 Feb 1996 17:17:45 -0500
  6. Organization: Montclair State University
  7. Message-ID: <harmon.824162937@pegasus.montclair.edu>
  8. References: <zakrzews.824018783@pegasus.montclair.edu>
  9. NNTP-Posting-Host: pegasus.montclair.edu
  10. X-Newsreader: NN version 6.5.0 #68 (NOV)
  11.  
  12. zakrzews@pegasus.montclair.edu (Tomas Zakrzewski) writes:
  13.  
  14. >Is it save to use a string library and stdio library with strings that are
  15. >no terminated by NULL charater. If is not, which function may not work correctly
  16. >and what would happen with non termianded string if a function is applied to
  17. >that string.
  18.  
  19.    Short answer, No.  In C convention, all "strings" are null-terminated.
  20. This is a sort of formal protocol that all arrays of characters, etc, must
  21. adhere to for the string functions to operate properly on them.  The specs
  22. for the string functions will likely explain that any (char *)'s they expect
  23. as arguments must be Null-terminared (with an ASCII '\0', such a string con-
  24. vention is also sometimes referred to as ASCIIZ strings).  If they are not
  25. Null-terminated, the best you can expect is they will continue their proces-
  26. sing past the end of your string until they do find a null character, '\0'.
  27.  
  28.    The ASCIIZ string convention of C is different from other languages like
  29. Pascal, where a leading byte contains the string length and the string follows.
  30. Conversion is generally straightforward, and must be performed before any   
  31. calls you may make to libraries written in languages with other conventions
  32. for handling strings.
  33.                                                       -- Stone
  34. --
  35. # Derek Harmon (aka Stonelight)    harmon@pegasus.montclair.edu
  36. # - Computer Science Undergrad, Montclair State University, NJ
  37. # - My views are my own, nobody else is this creative.  3;)>
  38. ... Eat prune yogurt for that get-up-and-go feeling.
  39.